from odoo import api, fields, models


class RpMarketingScheduleLog(models.Model):
    _name = 'rp.marketing.schedule.log'
    _description = '任务日志'

    code = fields.Char(string='编码', default='RM_SCL/****', copy=False, index=True)
    origin_from = fields.Selection(string='来源', selection=[('system', '系统'), ('business', '运营人员')])
    operation_person = fields.Many2one(string='操作人', comodel_name='res.users', copy=False, index=True)
    reference_record = fields.Many2one(string='关联记录', comodel_name='rp.marketing.auto.schedule', copy=False)
    schedule_type = fields.Selection(string='类型', selection=[('auto', '自动任务'), ('manual', '手动任务')], copy=False)
    target_customers = fields.Many2many(string='用户', comodel_name='rp.customer', column1='schedule_id', column2='rp_customer_id', relation='schedule_customer_relation', copy=False)
    operation_desc = fields.Char(string='操作描述', copy=False)
    date_create = fields.Datetime(string='创建时间', default=fields.Datetime.now(), copy=False, index=True)

    @api.model_create_multi
    def create(self, vals_list):
        for vals in vals_list:
            vals['code'] = self.env['ir.sequence'].next_by_code('rp.marketing.schedule.log') or '/'
        return super(RpMarketingScheduleLog, self).create(vals_list)
